package model

import (
	"errors"
	"saleforce/sf-backend-user/constant"
	"time"
)

type DepartmentExtModel struct {
	Id          int64     `gorm:"primary_key;column:id;type:bigint" json:"id"`
	DepId       int64     `gorm:"column:dep_id;type:bigint" json:"dep_id"`
	UserId      string    `gorm:"column:user_id;type:varchar(255)" json:"user_id"`
	WorkNo      string    `gorm:"column:work_no;type:varchar(255)" json:"work_no"`
	Position    string    `gorm:"column:position;type:varchar(255)" json:"position"`
	Description string    `gorm:"column:description;type:text" json:"description"`
	Created     time.Time `gorm:"column:created;type:datetime" json:"created"`
	Updated     time.Time `gorm:"column:updated;type:datetime" json:"updated"`
}

func (d DepartmentExtModel) GetRelationsByUserId(userId string) ([]DepartmentExtModel, error) {
	var lst []DepartmentExtModel
	tx := constant.Db.Model(d).Where("user_id = ?", userId).Find(&lst)
	if tx.Error != nil {
		return nil, errors.New("Database error")
	}
	return lst, nil
}

func (DepartmentExtModel) TableName() string {
	return "sf-department-ext"
}
